import axios from 'axios'
const baseURL = 'http://localhost:3000'

const HttpGet = (options) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseURL + options.url,
      method: 'GET',
      params: options.params
    })
      .then(res => {
        resolve(res.data)
      })
      .catch(err => {
        reject(err)
      });a
  })
}

const HttpPost = (options) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseURL + options.url,
      method: 'POST',
      data: options.data
    })
      .then(res => {
        resolve(res.data)
      })
      .catch(err => {
        reject(err)
      });
  })
}

const getHotData = () => {
  return new Promise((resolve, reject) => {
    axios({
      url: 'https://apis.tianapi.com/networkhot/index?key=a8b252e1957ebb55e705ced204a6e83e',
      method: 'GET',
    })
      .then(res => {
        resolve(res.data)
      })
      .catch(err => {
        reject(err)
      });
  })
}

export {
  HttpGet,
  HttpPost,
  getHotData
}